home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Textdisplayers / MoreIsBetter / v.c < prev    next >
C/C++ Source or Header  |  1996-09-26  |  3KB  |  119 lines

  1. /*                      Why Settle For LESS ?
  2.  
  3. This program runs More as a workbench process from the Cli, so that it will
  4. make a separate window like Less.  Yes, Virginia, I like More better than
  5. Less.  Especially this version where I DiskX'd the window specification to
  6. be borderless on the topmost screen (using ConMan 1.3).  There's little
  7. point in using this from CLImax without that DiskX'd version.  It looks for
  8. More on the resident list.  If it isn't found there, it checks
  9. SYS:Utilities/More, and then C:More.  Hopefully, this program is "pure" like
  10. More itself.
  11.  
  12. God DAMN, it works!  5/15/89 (Lake Jawi Day.)  By Paul Kienitz, public domain.
  13. */
  14.  
  15.  
  16. #include <exec/exec.h>
  17. #include <workbench/startup.h>
  18. #include <libraries/dosextens.h>
  19. #include <functions.h>
  20. #include <Paul.h>
  21.  
  22.  
  23. /* I think we're pure, basically...  the one variable that gets different
  24. values on different runs is _savsp, which gets set by crt0.  But that's
  25. cool, because it's never referred to.  Tests find no problems. */
  26.  
  27.  
  28. struct theResidents {
  29.     BPTR next;
  30.     long usecount;
  31.     BPTR seglist;
  32.     ubyte namelength;
  33.     char name[1];
  34. };
  35.  
  36.  
  37.  
  38. bool CBsame(c, r) str c; struct theResidents *r;
  39. {
  40.     str bb = &r->name[0];
  41.     ushort l = r->namelength;
  42.     for ( ; l && *c; l--, c++, bb++)
  43.     if (toupper(*c) != toupper(*bb)) return (false);
  44.     return (!l && !*c);
  45. }
  46.  
  47.  
  48.  
  49. BPTR FindResident(s) str s;
  50. {
  51.     extern struct DosLibrary *DOSBase;
  52.     struct DosInfo *dd;
  53.     struct theResidents *rr;
  54.     dd = gbip(((struct RootNode *) DOSBase->dl_Root)->rn_Info);
  55.     for (rr = gbip((BPTR) dd->di_NetHand); rr; rr = gbip(rr->next))
  56.     if (CBsame(s, rr))
  57.         return (rr->seglist);
  58.     return (null);
  59. }
  60.  
  61.  
  62.  
  63. str Chew(alen, aptr) long alen; str aptr;
  64. {
  65.     while (alen && aptr[alen - 1] <= ' ') aptr[--alen] = 0;
  66.     if (*aptr == '"') {
  67.     if (aptr[alen - 1] == '"') aptr[--alen] = 0;
  68.     aptr++;
  69.     }
  70.     if (aptr[alen]) aptr[--alen] == 0;        /* desperation meets crudity */
  71.     if (alen && !(alen == 1 && *aptr == '?'))
  72.     return (aptr);
  73.     else return (null);
  74. }
  75.  
  76.  
  77.  
  78. struct WBStartup wbminit = { { {null, null, NT_MESSAGE, 1, null}, null, 40},
  79.                  null, null, 1L, null, null};
  80.  
  81.  
  82. long _main(alen, aptr) long alen; str aptr;
  83. {
  84.     BPTR mo = FindResident("More");
  85.     APTR con;
  86.     bool loadsegged = false;
  87.     struct Process *me = (adr) FindTask(null);
  88.     struct MsgPort *port, *myport = &me->pr_MsgPort;
  89.     struct WBStartup wbm;
  90.     struct WBArg args[2];
  91.  
  92.     if (!mo) {
  93.     if (mo = LoadSeg("SYS:Utilities/More"))
  94.         loadsegged = true;
  95.     else if (mo = LoadSeg("C:More"))
  96.         loadsegged = true;
  97.     else {
  98.         Write(Output(),
  99. "Can't find More in resident list, SYS:Utilities, or C:.\n", 56L);
  100.         return (10);
  101.     }
  102.     }
  103.     port = (adr) CreateProc("More used by V", 0L, mo, 4000L);
  104.     wbm = wbminit;
  105.     args[0].wa_Lock = args[1].wa_Lock = me->pr_CurrentDir;
  106.     args[0].wa_Name = "More";
  107.     if (args[1].wa_Name = Chew(alen, aptr)) wbm.sm_NumArgs = 2;
  108.     wbm.sm_Process = port;
  109.     wbm.sm_Message.mn_ReplyPort = myport;
  110.     wbm.sm_Segment = mo;
  111.     wbm.sm_ArgList = &args[0];
  112.     /* what the fuck is ToolWindow for? */
  113.     PutMsg(port, &wbm);
  114.     WaitPort(myport);
  115.     GetMsg(myport);    /* flush reply */
  116.     if (loadsegged) UnLoadSeg(mo);
  117.     return (0);
  118. }
  119.